<?php
    class block_categoryLeftBlock_controller extends controllerBase
    {
        public function process()
        {
            $oDatabase = new database();
            $sCurrentUri = URL::getLink('category/id/'.$this->iId); 
            $this->aParams['sCurrentUri'] = $sCurrentUri;

            if(!caching::hasCache('aCategories'))
            {
                $aMenus = caching::createCacheMenu();       
            }
            else
            {
                $aMenus = caching::getCache('aCategories');
            }
            // Get Root Category
            $this->aParams['aRootCategories'] = $aMenus['child'];
            
            if($this->sController == 'category')
            {
                $aPCategories = array();
                $uri = URL::getLink('category/id/'.$this->iId);
                $aCurrentCategory = $aMenus['sub'][$uri];
                $this->aParams['aRootCategory'] = $aMenus['pRoot'][$uri];
                $sTemUri = $uri;
                while(true)
                {
                    $aTempCurrent = $aMenus['sub'][$sTemUri];
                    if(isset($aTempCurrent['pCategory']))
                    {
                        $sTemUri = $aMenus['sub'][$aTempCurrent['pCategory']]['uri'];
                        $aPCategories[] = $aMenus['sub'][$aTempCurrent['pCategory']];
                    }
                    else
                    {
                        break;
                    }
                }

                $this->aParams['pCategories'] = $aPCategories;

                if(isset($aCurrentCategory['pCategory']))
                {
                    $aCloseParent = $aMenus['sub'][$aCurrentCategory['pCategory']];
                    $this->aParams['subCategory'] = $aCloseParent['child'];
                }

                if(isset($aCurrentCategory['child']))
                {
                    $this->aParams['aSubCategoriesOfCurrent'] = $aCurrentCategory['child'];
                }
            }
        }
    }
?>
